package com.cn.wanxi.servlet;

import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.INewsService;
import com.cn.wanxi.service.impl.NewsServiceImpl;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/BackNewsFindById")
public class BackNewsFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String idString=req.getParameter("id");
        NewsModel newsModel=new NewsModel();
        newsModel.setId(Integer.parseInt(idString));
        INewsService iNewsService=new NewsServiceImpl();
        newsModel=iNewsService.findById(newsModel);


        JSONArray jsonArray = JSONArray.fromObject(newsModel);
        resp.getWriter().println(jsonArray);
    }
}
